package com.wenwei.sharebox.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wenwei.sharebox.R;
import com.wenwei.sharebox.bean.GoodCateBean;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/7/7.
 */
public class CateGoryRightAdapter extends RecyclerView.Adapter<CateGoryRightAdapter.MyViewHolder> {

    private Context mContext;
    private CateGorySubAdapter mSubAdapter;

    private CallBack mCallBack;

    public interface CallBack {
        void onItemClick(int id,String name);
    }

    private List<GoodCateBean.ShopTweClassesBean> mList;

    public void setDataList(List<GoodCateBean.ShopTweClassesBean> list) {
        this.mList = list;
    }

    public CateGoryRightAdapter(CallBack callBack) {
        this.mCallBack = callBack;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        mContext = parent.getContext();
        return new MyViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_category_sub, null));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCallBack.onItemClick(mList.get(position).getId(),mList.get(position).getName());
            }
        });
        Glide.with(mContext).load(mList.get(position).getUrlImg()).into(holder.goodsImg);
        holder.goodsName.setText(mList.get(position).getName());
    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.goods_img)
        ImageView goodsImg;
        @Bind(R.id.goods_name)
        TextView goodsName;
        public MyViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

}
